#include<iostream>

using namespace std;

int ncases;
int amplitude, frequency;

void print(int start, int end, bool add) {
   if(add) {
      for(int i=start; i<=end; i++) {
         for(int j=0; j<i; j++) 
            cout << i;
         cout << endl;
      }
   }
   else {
       for(int i = start; i>= end; i--) {
          for(int j=0; j<i; j++)
             cout << i;
          cout << endl;
       } 
   }
}

void read() {
   cin >> ncases;
   for(int i=0; i<ncases; i++) {
      cin >> amplitude;
      cin >> frequency;
      for(int j=0; j<frequency; j++) {
         print(1, amplitude, true);
         print(amplitude-1, 1, false);
         if(j != frequency-1)
            cout << endl;
      }
   }
}

int main() {
   read();
   return 0;
}
